package app.netant.finishbook.yunxs;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class YunxsDetail extends BaseDetail {

	public YunxsDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.yunxs.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".Layout.no_h .Left .j_box .title h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".Layout.no_h .Left .j_box .info ul li");
		if(parts.size()>0){
			for(int i=0;i<parts.size();i++){
				String tags = parts.get(i).text();
				int idx = tags.indexOf("：");
				if(idx>0){
					String tagName = tags.substring(0,idx).trim();
					String tagValue = tags.substring(idx+1).trim();
					System.out.println("【Tag】:"+tagName+"="+tagValue);
					this.entity.setTag(tagName, tagValue);
				}
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".Layout.no_h .Left .j_box .words p");
		for(int i=0;i<parts.size();i++){
			String memo = parts.get(i).text();
			if(memo.startsWith("简介")){
				System.out.println("【Memo】："+memo);
				this.entity.setNovelMemo(memo);
				break;
			}
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".Layout.no_h .Left .j_box .read_btn .btn a.txt");
		if(parts.size()>0){
			String url = parts.get(0).attr("href");
			if(url.startsWith("/")){
				url = this.preHref + url;
			}
			YunxsDetail detail = new YunxsDetail(url);
			String href = detail.stepHref();
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
		
	}
	
	private String stepHref(){
		Elements parts = this.select(".Layout.no_h .Left .j_box .read_btn .down a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("/")){
				href = this.preHref + href;
			}		
			return href;
		}
		return null;
	}
	
	@Override
	public void analyseType() {

	}
	
	public static void main(String[] args) {
		YunxsDetail detail = new YunxsDetail("http://www.yunxs.com/songjiang/");
		detail.test();
	}



}
